//1. set this to the desired path
cd "~/Desktop/LAP_PSRM_Replication/"

//2. Import the core replication file
use "LAP_Replication_COOHWIUS.dta", clear

//3. Transform the Independent variables (no. of groups lobbying on a bill by type)
// Change missing to zero, use the Laplace smoothing procedure (add one), and take the natural log of the number

local group_types "G B N"

foreach g of local group_types{
gen lorgs_`g' = log(orgs_`g'+1)
replace porgs_`g'_O = 0 if porgs_`g'_O == . 
replace porgs_`g'_S = 0 if porgs_`g'_S == . 
gen lporgs_`g'_opp = log(porgs_`g'_O+1)
gen lporgs_`g'_supp = log(porgs_`g'_S+1)
}

//4. Transform the average sponsor ideal point to a measure of extremity.
// Multiple liberal (negative) scores by negative one, so it resembles an absolute value, without assuming zero is the midpoint)
gen spon_mean_ext = spon_mean 
replace spon_mean_ext = spon_mean * -1 if spon_mean < 0


//5. Mark any bill that has an article about it as salient
gen salient =  0
replace salient = 1 if articles > 0 


//6. Table one, first set up controls 
//make sure your machine has installed the reghdfe
//if not run the following code:
//ssc install reghdfe

//also make sure you have the ESTOUT package installed to make tables
//if not, run the following code:
//ssc install estout


global lpdd_controls_floor "salient spon_mean_ext if sg_vote < 4 "
global lpdd_controls_comm "salient spon_mean_ext if sg_vote >= 4 "
global lppd_absorb ", absorb(senate year sg_vote) cluster(bill_id)"
global lppd_absorb2 ", absorb(senate year sg_vote papmajor) cluster(bill_id)"


//Table 2:
eststo clear
eststo: reghdfe party_diff lorgs*  $lpdd_controls_floor & state == "us" $lppd_absorb2
eststo: reghdfe party_diff lorgs*  $lpdd_controls_floor & state == "co" $lppd_absorb2
eststo: reghdfe party_diff lorgs*  $lpdd_controls_floor & state == "oh" $lppd_absorb2
eststo: reghdfe party_diff lorgs*  $lpdd_controls_floor & state == "wi" $lppd_absorb2
esttab  , se label replace star(* 0.05 ** 0.01) ///
order(lorgs_N lorgs_B lorgs_G salient) b(2) se(2) ///
title("All: Fixed effects for session, chamber, vote type excluded).") ///
mtitles("us" "co" "oh" "wi") 


//Table 3:
eststo clear
eststo: reghdfe party_diff *_opp *_supp $lpdd_controls_comm & state == "co" $lppd_absorb2
eststo: reghdfe party_diff *_opp *_supp $lpdd_controls_floor & state == "co" $lppd_absorb2
eststo: reghdfe party_diff *_opp *_supp $lpdd_controls_floor & state == "wi" $lppd_absorb2

esttab , se label replace star(* 0.05 ** 0.01) ///
order(lporgs_N_opp lporgs_N_supp lporgs_B_opp lporgs_B_supp   lporgs_G_opp lporgs_G_supp salient) b(2) se(2) ///
title("COWI: Fixed effects for session, chamber, vote type excluded).") ///
mtitles("comm" "floor" "floor-WI") 


